package com.zhenwei.controller;

import com.zhenwei.domain.Customer;
import com.zhenwei.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    //查询全部
    @RequestMapping("/findAll")
    public String findAll(Model model){
        List <Customer> customers = customerService.findAll();
        model.addAttribute("customers", customers);
        return "list";
    }

    //更改前先进行查询,将原信息反馈到更改的界面上
    @RequestMapping("/findById")
    public String findById(Model model,String custId){
        System.out.println(custId);
        Customer customer = customerService.findById(custId);
        System.out.println(customer);
        model.addAttribute("customer", customer);
        return "edit";
    }

    //对信息进行更新并返回查看全部页面
    @RequestMapping("/update")
    public String update(Customer customer){
        customerService.update(customer);
        return "redirect:findAll";
    }

}
